/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  com.jfinal.template.Engine
 *  com.jfinal.template.Template
 *  io.idc.core.log.publisher.MagicLogPublisher
 *  org.springframework.stereotype.Component
 */
package com.chenfan.magic.resolver;

import com.chenfan.magic.core.IdcEngineEntry;
import com.chenfan.magic.core.MagicLogPublisher;
import com.chenfan.magic.entity.TTLDetailModel;
import com.jfinal.template.Engine;
import com.jfinal.template.Template;

import org.springframework.stereotype.Component;

import java.io.StringWriter;
import java.io.Writer;
import java.util.Map;
/**
 * @author lm
 */
@Component
public class EnjoyResolver
implements __IResolver {
    public static final String TYPE_CODE = "enjoy";

    @Override
    public String resolve(Map<String, Object> idcRuntimePool, String templateContent, Map<String, Object> paramMap) {
        TTLDetailModel ttlDetailModel = new TTLDetailModel();
        ttlDetailModel.start();
        String result = "";
        try {
            Engine engine = Engine.use();
            StringWriter writer = new StringWriter();
            Template template = engine.getTemplateByString(templateContent, true);
            template.render(paramMap, (Writer)writer);
            result = writer.toString();
            MagicLogPublisher.publishResolverEvent((String)TYPE_CODE, (String)templateContent, (String)result, paramMap, (String)(ttlDetailModel.end().getTtl() + ""));
        }
        catch (Exception e) {
            e.printStackTrace();
            MagicLogPublisher.publishResolverEvent((String)TYPE_CODE, (String)templateContent, (String)result, paramMap, (String)(ttlDetailModel.end().getTtl() + ""), (Throwable)e);
            IdcEngineEntry.throwException(idcRuntimePool, null, e);
        }
        return result;
    }
}

